package com.org.web.handle.index.controller;

import com.org.platform.model.ResultModel;
import com.org.web.handle.user.service.UserService;
import com.org.web.support.base.BaseController;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/** @author devg @Date 2020/2/26 10:50 */

@Slf4j
@RestController
@RequestMapping(value = {"/index"})
public class IndexController extends BaseController {

  @Autowired
  private UserService userService;

  @GetMapping(value = {"", "/"})
  public ModelAndView index(HttpServletRequest request) {
    String state = request.getParameter("state");
    String code = request.getParameter("code");
    log.info("code:{},state:{}",code,state);
    userService.wechatLogin(code,state);
    Map<String, Object> model = new HashMap<>();
    model.put("footNav","index");
    return modelAndView("/front/index",model);
  }

  @GetMapping("/test.htm")
  public ResultModel test() {
    return ResultModel.newSuccess();
  }
}
